// pages/new-pages/my-evaluate/my-evaluate.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hasMore: true,
    pageSize: 10,
    pageIndex: -1,
    commentList: []
  },
  //获取我的评价
  getMyCommentEvaluate() {
    if (!this.data.hasMore) {
      return;
    }
    let pageIndex = ++this.data.pageIndex;
    this.setData({
      pageIndex: pageIndex
    })
    let data = {
      userInfoId: app.userInfo.Id,
      pageIndex: pageIndex,
      pageSize: this.data.pageSize
    }
    console.log("getMyCommentEvaluate" + JSON.stringify(data));
    wx.showLoading({
      title: '加载中...',
      mask: true
    });
    let that = this;
    wx.request({
      url: app.globalData.serverAddress.getMyCommentEvaluate,
      data: data,
      header: {
        'Authorization': "Bearer " + app.globalData.token
      },
      method: 'GET',
      success: function(res) {
        console.log("getMyCommentEvaluate response", res);
        if (res.statusCode == 200) {
          if (res.data.CodeStatus == 20000) {
            let count = res.data.BodyContent.TotalCount;
            let flag = (that.data.pageIndex + 1) * that.data.pageSize < count;
            let newList = that.data.employeeList.concat(res.data.BodyContent.List);
            that.setData({
              hasMore: flag,
              commentList: newList
            })
          } else {
            that.setData({
              hasMore: false
            });
          }
        } else {
          Toast("请求失败了，请检查网络连接！");
        }
      },
      fail: function(res) {
        console.log("getMyCommentEvaluate fail", res)
      },
      complete: function(res) {
        wx.hideLoading()
      },
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getMyCommentEvaluate();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.getMyCommentEvaluate()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})